
function hanadleDate(value){
	if(value == undefined){
		return;
	}
	// let date = new Date(value * 1000);
	let date = new Date(value);
	//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	let y = date.getFullYear();
	let MM = date.getMonth() + 1;
	MM = MM < 10 ? ('0' + MM) : MM; //月补0
	let d = date.getDate();
	d = d < 10 ? ('0' + d) : d; //天补0
	let h = date.getHours();
	h = h < 10 ? ('0' + h) : h; //小时补0
	let m = date.getMinutes();
	m = m < 10 ? ('0' + m) : m; //分钟补0
	let s = date.getSeconds();
	s = s < 10 ? ('0' + s) : s; //秒补0
	// return y + '-' + MM + '-' + d; //年月日
	return y + '-' + MM + '-' + d + ' ' + h + ':' + m+ ':' + s; //年月日时分秒
}

function formatDate(value) {
	let dateStr = hanadleDate(value)
	let date = new Date(dateStr)
	let diffValue = new Date().getTime() - date.getTime()  // 时间差
	let mValue = diffValue / (1000 * 60)  // 分
	let hValue = diffValue / (1000 * 60 * 60)  // 小时
	let dayValue = diffValue / (1000 * 60 * 60 * 24)  // 天
	let result = ''
	if (date.getFullYear() !== new Date().getFullYear()) {  // 不同年
	  result = dateStr.substring(0, 16)
	} else {  // 同年
	  if (dayValue  > 6) {  // 时间差大于一周
	    result = dateStr.substring(5, 16)
	  } else if (dayValue  >= 1 && dayValue  <= 6) {  // 时间差一天之外 一周之内
	    result = parseInt(dayValue ) + '天前'
	  } else if (hValue >= 1 && hValue <= 23) {
	    result = parseInt(hValue ) + '小时前'
	  } else if (mValue >= 1 && mValue  <= 59) {
	    result = parseInt(mValue ) + '分钟前'
	  } else if (diffValue >= 0 && diffValue  <= 60000 ) {
	    result = '刚刚'
	  }
	}
	return result
}

export{
	formatDate,
	hanadleDate
}
